import { useConfigStore } from '@/stores/modules/configStore';
const config = useConfigStore();
const status = {
  loadingCount: 0,
  //不需要加载动画的api路径
  whitelist: config.status.loadingWhitelist
};
//返回 停止loading回调
const startLoading = (httpUrl) => {
  if (status.whitelist.includes(httpUrl)) {
    //预防误删loadingCount
    return () => {};
  }
  status.loadingCount++;
  if (status.loadingCount <= 1) {
    uni.showLoading({
      content: '加载中...',
      delay: 500
    });
  }
  return closeLoading;
};

const closeLoading = () => {
  status.loadingCount--;
  if (status.loadingCount === 0) uni.hideLoading();
};
export default {
  startLoading
};
